package com.bigdata.core.transformations

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * sortByKey 默认按照key去排序，作用在K,V格式的RDD上
 */
object Demo5_sortByKey {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("sortByKey")
    conf.setMaster("local")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val infos: RDD[(String, String)] = sc.parallelize(Array[(String, String)]
      (("f", "1"),("f", "3"),("f", "2"), ("a", "a"), ("c", "c"), ("b", "b")))
    val result: RDD[(String, String)] = infos.sortByKey(false)
    result.foreach(println)

    sc.stop()
  }
}
